package com.liwen.kefu.controller;

import com.liwen.kefu.common.result.CommonCode;
import com.liwen.kefu.common.result.ResponseResult;
import com.liwen.kefu.service.KeFuDataActionService;
import com.liwen.kefu.vo.BaseDataVo;
import com.liwen.kefu.vo.DataImportVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Liwen
 * @createTime: 2024/11/9
 * @description:
 */

@RestController
@ControllerAdvice
@RequestMapping(value = "/kefu")
@Api(tags = "数据操作")
public class KeFuDataActionController {

    @Autowired
    private KeFuDataActionService keFuDataActionService;


    @ApiOperation("添加hive查询sql")
    @PostMapping("/add/sql")
    public ResponseResult addSql(@RequestBody DataImportVo dataImportVo) {
        try {
            return keFuDataActionService.addQuerySql(dataImportVo);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.ERROR(CommonCode.CONFIG_FAIL, e);
        }
    }

    @ApiOperation("获取配置")
    @GetMapping(value = {"/config"})
    public ResponseResult getConfig(@ApiParam(value = "模块|表名|库名，模糊查询", required = false) String keyWord) {
        try {
            return keFuDataActionService.getConfig(keyWord);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.ERROR(CommonCode.FAIL);
        }
    }

    @ApiOperation("hive->测试环境")
    @PostMapping(value = "/hive/to/mysql")
    public ResponseResult hiveImportDataToSql(@RequestBody BaseDataVo baseDataVo) {
        String userId = baseDataVo.getUserId();
        if (StringUtils.isEmpty(userId)) {
            return ResponseResult.ERROR(CommonCode.QUERY_USER_ID_FAIL, "userId等于null");
        }
        return keFuDataActionService.hiveImportDataToSql(baseDataVo);
    }

    /*@ApiOperation("删除测试数据")
    @PostMapping(value = "/delete/data")
    public ResponseResult deleteDataByMobilNo(@RequestBody BaseDataVo baseDataVo) {
        String userId = baseDataVo.getUserId();
        if (StringUtils.isEmpty(userId)) {
            return ResponseResult.ERROR(CommonCode.QUERY_USER_ID_FAIL, "userId等于null");
        }

        return keFuDataActionService.deleteDataByMobilNo(baseDataVo);
    }*/

  /*  @PostMapping(value = "/test")
    public ResponseResult test(@RequestBody BaseDataVo baseDataVo) {
        String userId = baseDataVo.getUserId();
        if (StringUtils.isEmpty(userId)) {
            return ResponseResult.ERROR(CommonCode.QUERY_USER_ID_FAIL, "userId等于null");
        }
        return ResponseResult.SUCCESS(CommonCode.SUCCESS);
    }*/

}
